package com.future.jdbc;

import java.io.InputStream;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;
import java.util.Properties;

public class JdbcDemo1 {

	public static void main(String[] args) throws Exception {

		String driverClass = "";
		String url = "";
		String user = "";
		String password = "";

		Properties pro = new Properties();
		InputStream in = JdbcDemo1.class.getClassLoader().getResourceAsStream("db.properties");
		pro.load(in);

		driverClass = pro.getProperty("driverClass");
		url = pro.getProperty("url");
		user = pro.getProperty("user");
		password = pro.getProperty("password");

		Class.forName("com.mysql.jdbc.Driver");
		// Connection connection =
		// DriverManager.getConnection("jdbc:mysql://localhost:3306/power","root","root");
		// Properties properties = new Properties();
		// InputStream in =
		// JdbcDemo1.class.getClassLoader().getResourceAsStream("db.properties") ;
		// properties.load(in);
		// Connection connection =
		// DriverManager.getConnection("jdbc:mysql://localhost:3306/power",properties);
		Connection connection = DriverManager.getConnection(url, user, password);
		Statement statement = connection.createStatement();

		ResultSet resultSet = statement.executeQuery("select * from tb_cms_city;");

		while (resultSet.next()) {
			System.out.println(resultSet.getInt("id") + ":" + resultSet.getString("name"));
		}

		resultSet.close();
		statement.close();
		connection.close();
	}

}
